<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .w {
            width: 1226px;
            margin: 0 auto;
        }

        .header {
            height: 150px;
            background: grey;
        }

        .wrapNav {
            height: 45px;
        }

        .navBar {
            background-color: #ff0;
            width: 100%;
        }
        .fixed{
            position: fixed;
            top: 0;
            width: 100%;
        }
        .nav {
            display: flex;
            height: 45px;
            line-height: 45px;
        }

        .nav li {
            flex: 1;
            border: 1px solid #000;
            text-align: center;
        }

        .nav li+li {
            border-left: 0;
        }

        .main .part {
            height: 400px;
            text-align: center;
            line-height: 400px;
            border: 1px solid #000;
        }

        .main .part+.part {
            border-top: 0;
        }

        .tips {
            width: 100%;
            line-height: 45px;
            position: fixed;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            text-align: center;
            display: none;
        }

        .back {
            width: 45px;
            height: 45px;
            border: 1px solid #333;
            text-align: center;
            line-height: 45px;
            position: fixed;
            right: 5px;
            bottom: 50px;
            display: none;
        }
    </style>
</head>

<body>
    <div class="header w"></div>
    <div class="wrapNav">
        <div class="navBar">
            <ul class="nav w">
                <li>link_01</li>
                <li>link_02</li>
                <li>link_03</li>
                <li>link_04</li>
                <li>link_05</li>
                <li>link_06</li>
            </ul>
        </div>
    </div>
    <div class="main w">
        <div class="part">part_01</div>
        <div class="part">part_02</div>
        <div class="part">part_03</div>
        <div class="part">part_04</div>
        <div class="part">part_05</div>
        <div class="part">part_06</div>
        <div class="part">part_07</div>
        <div class="part">part_08</div>
        <div class="part">part_09</div>
        <div class="part">part_10</div>
    </div>
    <div class="tips">到达底部</div>
    <div class="back">top</div>
</body>
<script>

    var navBar = document.getElementsByClassName("navBar")[0];
    var header = document.getElementsByClassName("header")[0];


    var tips = document.getElementsByClassName("tips")[0];
    // console.log(buttom);
    window.onscroll = function () {
        var scrollTop = document.documentElement.scrollTop;
        // console.log(scrollTop);
        //吸顶效果
        var headerHeight = header.clientHeight;
        if (scrollTop >= headerHeight) {
            // navBar.style.position = "fixed";
            // navBar.style.top = "0";
            // navBar.style.width = "100%";
            navBar.classList.add("fixed");
        } else {
            // navBar.style.position = "static";
            navBar.classList.remove("fixed");
        }

        //滚动条到达底部时的效果
        var clientHeight = document.documentElement.clientHeight;
        var scrollHeight = document.documentElement.scrollHeight;
        var buttom = scrollHeight - clientHeight;
        if (scrollTop >= buttom) {
            tips.style.display = "block";
            back.style.display = "block";

            setTimeout(function () {
                tips.style.display = "none";
            }, 500)
        } else {
            tips.style.display = "none";
            back.style.display = "none";
        }
    }

    //回到顶部的效果
    var back = document.getElementsByClassName("back")[0];
    // back.style.display = "block";
    back.onclick = function () {
        document.documentElement.scrollTop = 0;
        // window.scrollTo(0,0);

    }
</script>

</html>